package sUtils;

public class Log {

    String [] history = null;
    File logfile = null;

    public Log( int historySize )
    {
        if (historySize>0)
        {
            history = new String[historySize];
            for ( int i=0; i<history.length; i++ ) history[i]="";
        }
    }

    public boolean open( String name )
    {
        logfile = new File();
        return logfile.create(name);
    }

    public void close()
    {
        if (logfile!=null)
        {
            logfile.close();
            logfile=null;
        }
    }

    public void push( String s, boolean add )
    {
        if (history!=null)
        {
            if (add && history.length>1)
                for ( int i=history.length-1; i>0; i-- ) history[i]=history[i-1];
            history[0]=s;
        }
        if (logfile!=null)
        {
            logfile.writeStr( s );
            if (add) logfile.writeStr( "\r\n" );
        }
    }
}
